package com.csxh.web.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.csxh.web.bean.QueryCondition;
import com.csxh.web.dao.QueryConditionDao;

/**
 * 服务层：查询条件服务类
 * @author Administrator
 *
 */
public class QueryConditionService {

	
	public List<QueryCondition> build(Class<?> clazz){
		
		List<QueryCondition> list=new ArrayList<QueryCondition>();
		QueryConditionDao dao=new QueryConditionDao();
		
		Map<String,Class<?>> map=dao.findFieldSchema(clazz);
		
		for (Map.Entry<String, Class<?>> entry : map.entrySet()) {
			
			QueryCondition qc=new QueryCondition();
			
			//字段名称
			qc.setFieldName(entry.getKey());
			//生成条件表达式
			qc.setExpression(entry.getValue());
			
			list.add(qc);
		}
		
		return list;
		
	}

	public List<QueryCondition> build(Class<?> clazz, String[] includeFields, String[] excludeFields) {
		
		List<QueryCondition> list=new ArrayList<QueryCondition>();
		QueryConditionDao dao=new QueryConditionDao();
		
		Map<String,Class<?>> map=dao.findFieldSchema(clazz, includeFields, excludeFields);
		
		for (Map.Entry<String, Class<?>> entry : map.entrySet()) {
			
			QueryCondition qc=new QueryCondition();
			
			//字段名称
			qc.setFieldName(entry.getKey());
			//字段显示名称
			qc.setFieldText(entry.getKey());
			//生成条件表达式
			qc.setExpression(entry.getValue());
			
			list.add(qc);
		}
		
		return list;
	}
}
